<?php

use App\Admin\Extensions\WangEditor;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Grid\Column;
use Zhaiduting\ColumnRelation\Relate;
use App\Admin\Extensions\MyStock;
use App\Admin\Extensions\MyRadio;

Admin::js('common/hide-footer.js');

// 覆盖`admin`命名空间下的视图
Encore\Admin\Form::forget(['map', 'editor']);
Form::extend('editor', WangEditor::class);
Column::extend('relate', Relate::class);
Column::extend('mystock', MyStock::class);
Form::extend('myradio', MyRadio::class);



Grid::init(function (Grid $grid) {
	$adminRoute = [
    	'admin.auth.users.index',
	    'admin.auth.roles.index',
	    'admin.auth.permissions.index'
    ];
	if(!in_array(\Illuminate\Support\Facades\Route::currentRouteName(), $adminRoute)){
		$grid->index('序号');
		
	    $grid->rows(function ($row, $number) {
	        $row->column('index', $number + 1);
	    });
	}
	
    $grid->expandFilter();
    $grid->model()->orderByDesc('created_at');

    $grid->disableExport();
    $grid->actions(function (Grid\Displayers\Actions $actions) {
        $actions->disableView();
    });
    // 管理员去除id筛选增加名称筛选
    if(in_array(\Illuminate\Support\Facades\Route::currentRouteName(), $adminRoute)) {
    	
    	if (\Illuminate\Support\Facades\Route::currentRouteName() === 'admin.auth.users.index') {
    		$grid->model()->orderByDesc('created_at')
	        ->where('store_id', 0);
	    }
    	
        $grid->filter(function ($filter) {
            $filter->disableIdFilter();
            $filter->like('name', '名称');
	    });
    }
});
Form::init(function (Form $form) {

    $form->disableViewCheck();

    $form->tools(function (Form\Tools $tools) {

        $tools->disableView();
    });
});
